package com.zslibrary.Protocol;

import com.zslibrary.Enum.CommunicationError;
import com.zslibrary.Enum.PipeResultDefine;
import com.zslibrary.Enum.Protocol;
import com.zslibrary.Enum.StatusDefine;
import com.zslibrary.Pipe.Pipe;
import com.zslibrary.Structure.GeneralRequestStruct;
import com.zslibrary.Structure.MessageStruct;
import com.zslibrary.Structure.ReplyStruct;
import com.zslibrary.Tools.FrameBuilder;

public class QueryBoardStatus {
    private static int mBoardStates;
    public static int queryBoardStatus(Pipe pipe){
        GeneralRequestStruct request=new GeneralRequestStruct();
        request.requstId= Protocol.MSG_GET_BOARD_STATUS;
        request.dataLength=0;
        Pipe.HandleMessageCallback callback=new Pipe.HandleMessageCallback() {
            @Override
            public Boolean handle(MessageStruct[] messages) {
                for(MessageStruct message:messages){
                    FrameBuilder builder=new FrameBuilder(message.messageData);
                    mBoardStates=builder.popData(4);
                }
                return true;
            }
        };
        int result= pipe.synchronousPipe(request,callback);
        if(result!= PipeResultDefine.SYNC_OK)
            return -1;
        return mBoardStates;
    }
}
